package com.thz.houserental.infrastructure.exception;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.springframework.http.HttpStatus;


@Data
public class ParameterException extends HttpException {

    public ParameterException() {
        this.code = HttpStatus.BAD_REQUEST.value();
        this.message = HttpStatus.BAD_REQUEST.getReasonPhrase();
    }

    public ParameterException(int code) {
        this.code = code;
        String codeMessage = ExceptionCodeConfiguration.getMessage(code);
        if(StrUtil.isNotEmpty(codeMessage)) {
            this.message = codeMessage;
        } else {
            this.message = HttpStatus.BAD_REQUEST.getReasonPhrase();
        }
    }
}
